<?php 

class Cocur_Config_Yml extends Zend_Config
{
	
	public function __construct($filename, $section = null)
	{
		if (empty($filename))
		{
        	/**
             * @see Zend_Config_Exception
             */
            require_once 'Zend/Config/Exception.php';
            throw new Zend_Config_Exception('Filename is not set');
		}
		
		if (!file_exists($filename))
		{
			/**
			 * @see Zend_Config_Exception
			 */
			require_once 'Zend/Config/Exception.php';
			throw new Zend_Config_Exception('File "' . $filename . '" does not exist.');
		}
		
		// Load spyc for YAML parsing.
		require_once 'spyc/spyc.php';
		
		$yaml = Spyc::YAMLLoad($filename);
		
		if (null == $section)
		{
			parent::__construct($yaml);
		}
		else
		{
			parent::__construct($yaml[$section]);
		}
	}
	
}